package com.example.swimmingpool.service.goods_type;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.swimmingpool.entity.goods_type.GoodsType;
import com.example.swimmingpool.mapper.goods_type.GoodsTypeMapper;
import com.example.swimmingpool.qo.goodsType.GoodsTypeQo;
import com.example.swimmingpool.vo.goods_type.GoodsTypeVo;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GoodsTypeService extends ServiceImpl<GoodsTypeMapper, GoodsType> {
    public int update(GoodsTypeVo vo) {
        var goodsType = BeanUtil.copyProperties(vo, GoodsType.class);
        return this.getBaseMapper().updateById(goodsType);

    }

    public List<GoodsTypeVo> getGoodsTypeList(GoodsTypeQo qo) {
        List<GoodsType> list = this.lambdaQuery()
                .like(StrUtil.isNotBlank(qo.getTypeName()), GoodsType::getTypeName, qo.getTypeName())
                .like(StrUtil.isNotBlank(qo.getDescription()), GoodsType::getDescription, qo.getDescription())
                .eq(ObjectUtil.isNotNull(qo.getId()), GoodsType::getId, qo.getId()).list();
        return BeanUtil.copyToList(list, GoodsTypeVo.class);

    }
}
